﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ScreenMonitor.Common.Objects
{
    public sealed class SignResponceObject
    {

        private static object StaticLockObj = new object();
        private object LockObj = new object();

        public string Name { get; set; }
        public string StuID { get; set; }
        public byte[] ToByte()
        {
            lock (LockObj)
            {
                MemoryStream stream = new MemoryStream();
                BinaryWriter bw = new BinaryWriter(stream);
                bw.Write(Name);
                bw.Write(StuID);
                bw.Flush();
                byte[] r = stream.ToArray();
                bw.Close();
                return r;
            }
        }

        public static SignResponceObject FromByte(byte[] Data)
        {
            lock (StaticLockObj)
            {
                MemoryStream stream = new MemoryStream(Data);
                BinaryReader br = new BinaryReader(stream);
                SignResponceObject so = new SignResponceObject();
                so.Name = br.ReadString();
                so.StuID = br.ReadString();
                br.Close();
                return so;
            }
        }
    }
}
